package Javaa.Base;
//create an example of try catch many kinds of block for exception handling
// give more examples of different exceptions like ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException, NumberFormatException

public class ExceptionExample {
    public static void main(String[] args) {
        // Example of try-catch for ArithmeticException
        try {
            int result = 10 / 0;
        } catch (ArithmeticException e) {
            System.out.println("Caught an ArithmeticException: " + e.getMessage());
        }

        // Example of try-catch for ArrayIndexOutOfBoundsException
        try {
            int[] numbers = {1, 2, 3};
            int number = numbers[5];
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Caught an ArrayIndexOutOfBoundsException: " + e.getMessage());
        }

        // Example of try-catch for NullPointerException
        try {
            String str = null;
            System.out.println(str.length());
        } catch (NullPointerException e) {
            System.out.println("Caught a NullPointerException: " + e.getMessage());
        }

        // Example of try-catch for NumberFormatException
        try {
            String invalidNumber = "abc";
            int num = Integer.parseInt(invalidNumber);
        } catch (NumberFormatException e) {
            System.out.println("Caught a NumberFormatException: " + e.getMessage());
        }
    }
}